package de.fhhannover.inform.itteam.snmpnetviz;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

import org.snmp4j.util.TableEvent;

public class HelperFunctions {
	public static String getMacFromOidString(String oidString) {
		String result = "";
		String[] split = oidString.split("[.]");
		for (String p : split) {
			if (result.isEmpty()) result=result+getHexFromDez(new Integer(p).intValue());
			else result=result+":"+getHexFromDez(new Integer(p).intValue());
		}
		return result;
	}
	
	public static String getIpFromOidString(String oidString) {
		String result = "";
		
		String[] split = oidString.split("[.]");
		result=split[split.length-4]+"."+split[split.length-3]+"."+split[split.length-2]+"."+split[split.length-1];
		
		return result;
	}
	
	public static String getHexFromDez(int dez) {
		String result = Integer.toString(dez, 16);
		if (result.length()<2) result = "0"+result;
		return result;
	}
	
	public static HashMap<Integer, String> getHashmapFromOidTable(List<TableEvent> list) {
		if (list!=null) {
			HashMap<Integer, String> result = new HashMap<Integer, String>();
			
			Iterator<TableEvent> it = list.iterator();
			
			while(it.hasNext()) {
				TableEvent event = it.next();
				if (event.getIndex()!=null) {
					int key = new Integer(event.getIndex().toString()).intValue();
					result.put(key, event.getColumns()[0].toValueString());
				}
			}
			
			return result;
		}
		
		return null;
	}

}
